package com.lagou.demo.controller;

import com.lagou.demo.service.IDemoService;
import com.lagou.edu.mvcframework.annotations.LagouAutowired;
import com.lagou.edu.mvcframework.annotations.LagouController;
import com.lagou.edu.mvcframework.annotations.LagouRequestMapping;
import com.lagou.edu.mvcframework.annotations.Security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@LagouController
@LagouRequestMapping("/auth")
public class AuthController {

    /**
     * user name who have admin role can access
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouRequestMapping("/admin")
    @Security({"admin"})
    public String admin(HttpServletRequest request, HttpServletResponse response, String name) {
        System.out.println("auth:admin");
        try {
            response.getWriter().write("auth:admin");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "auth:admin";
    }

    /**
     * user name who have sale role can access
     * @param request
     * @param response
     * @param name
     * @return
     */
    @LagouRequestMapping("/sale")
    @Security({"sale","admin"})
    public String sale(HttpServletRequest request, HttpServletResponse response, String name) {
        System.out.println("auth:sale");
        try {
            response.getWriter().write("auth:sale");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "auth:sale";
    }
    
}
